package com.cb.spzx.manager.controller;

import com.cb.spzx.manager.service.SysMenuService;
import com.cb.spzx.model.entity.system.SysMenu;
import com.cb.spzx.model.vo.common.Result;
import com.cb.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "菜单管理")
@RestController
@RequestMapping(value = "/admin/system/sysMenu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @Operation(summary = "查询树形菜单")
    @GetMapping("/findNodes")
    public Result findNodes(){
        List<SysMenu> list=sysMenuService.findNodes();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "菜单添加")
    @PostMapping("/save")
    public Result saveMenu(@RequestBody SysMenu sysMenu){
        int result=sysMenuService.saveMenu(sysMenu);
        if(result>0){
            return Result.build(null,ResultCodeEnum.SUCCESS);
        }
        return Result.build(null,ResultCodeEnum.DATA_ERROR);
    }

    @Operation(summary = "菜单修改")
    @PutMapping("/updateById")
    public Result updateMenu(@RequestBody SysMenu sysMenu){
        int result=sysMenuService.updateMenu(sysMenu);
        if(result>0){
            return Result.build(null,ResultCodeEnum.SUCCESS);
        }
        return Result.build(null,ResultCodeEnum.DATA_ERROR);
    }

    @Operation(summary = "菜单删除")
    @DeleteMapping("/removeById/{id}")
    public Result deleteMenu(@PathVariable("id") Long id){
        int result=sysMenuService.deleteMenu(id);
        if(result>0){
            return Result.build(null,ResultCodeEnum.SUCCESS);
        }
        return Result.build(null,ResultCodeEnum.DATA_ERROR);
    }
}
